package org.example.security.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.core.constant.TokenConstants;
import org.example.security.handler.SecurityHandler;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;

/**
 * @author 小杰_cc
 * @version 1.0
 */

public class FrontInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 获取信息
        HashMap<String, String> map = new HashMap<>();
        map.put(TokenConstants.MEMBER_ID,request.getHeader(TokenConstants.MEMBER_ID));
        map.put(TokenConstants.MEMBER_NAME,request.getHeader(TokenConstants.MEMBER_NAME));
        SecurityHandler.setData(map);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        SecurityHandler.remove();
    }
}
